﻿//TODO: Would need to generalise to be useful
// Which charts, where (divs)
function createGraph(columnZeroTitle, columnOneTitle, originalData) {
    var dataArray = (function converter(jsonObject) {
        var arr = [];
        for (var prop in jsonObject) {
            arr.push([prop, jsonObject[prop]]);
        }
        return arr;
    })(originalData);

    var dashboard = new google.visualization.Dashboard(document.getElementById('dashboard_div'));
    var dashboard1 = new google.visualization.Dashboard(document.getElementById('dashboard1_div'));

    var gDT = new google.visualization.DataTable();
    gDT.addColumn(typeof dataArray[0][0], columnZeroTitle);
    gDT.addColumn(typeof dataArray[0][1], columnOneTitle);
    gDT.addRows(dataArray);

    var filter = new google.visualization.ControlWrapper({
        'controlType': 'NumberRangeFilter',
        'containerId': 'filter_div',
        'options': { 'filterColumnLabel': columnOneTitle }
    });

    var barChart = new google.visualization.ChartWrapper({
        'chartType': 'BarChart',
        'containerId': 'barchart_div',
        'options': {
            'width': 300,
            'height': 300,
            'legend': 'right'
        }
    });

    var lineChart = new google.visualization.ChartWrapper({
        'chartType': 'LineChart',
        'containerId': 'linechart_div',
        'options': {
            'width': 300,
            'height': 300,
            'legend': 'right'
        }
    });

    dashboard.bind(filter, barChart);
    dashboard1.bind(filter, lineChart);

    dashboard.draw(gDT);
    dashboard1.draw(gDT);
}